cards = [
    {'name': 'jerry', 'tel': '18700000', 'qq': '402256', 'email': '455@qq.com'},
    {'name': 'tom', 'tel': '15100000', 'qq': '333024', 'email': '125@163.com'},
]
def menu():
    print('''***************************
欢迎使用【名片管理系统】V1.0
1. 新建名片
2. 显示全部
3. 查询名片 -> 4. 修改名片 5. 删除名片
0. 退出系统
***************************''')


def create_new_card(name, tel, qq, email):
    card = {
        'name': name,
        'tel': tel,
        'qq': qq,
        'email': email
    }
    cards.append(card)
    print('Create a new business card successfully')


def show_all_card():
    for card in cards:
        print(card)


def query_card(kw):
    for card in cards:
        for k, v in card.items():
            if v == kw:
                return card
    else:
        return False


def modify_card(query_result, modify_category, modify_content):
    if modify_category in query_result:
        query_result[modify_category] = modify_content
        return query_result
    else:
        return False


def del_card(query_result):
    index = cards.index(query_result)
    cards.pop(index)
    print('Delete successfully!')


menu()
while True:
    option = int(input('Please input option number: '))
    if option == 1:
        name = input('Please input your name: ')
        tel = input('Please input your tel: ')
        qq = input('Please input your qq: ')
        email = input('Please input your email: ')
        create_new_card(name, tel, qq, email)
    elif option == 2:
        show_all_card()
    elif option == 3:
        kw = input('Please input the keyword for the query information: ')
        query_result = query_card(kw)
        if query_result:
            print(query_result)
            option2 = int(input('please input 4. modify card or 5. delete card: '))
            if option2 == 4:
                modify_category= input('Please input modify category: ')
                modify_content= input('Please input modify content ')
                modify_result = modify_card(query_result, modify_category, modify_content)
                if modify_result:
                    print(modify_result)
                else:
                    print('Card category wrong, please try again!')
            elif option2 == 5:
                del_card(query_result)
        else:
            print('Not found, please try again!')
    elif option == 0:
        print('Thank you for using us, welcome to visit us next time!')
        break
    else:
        print('Please try again!')